package spring.mybatis.mybatisScanXML;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.ImportResource;
import spring.mybatis.mapper.UserMapper;
import spring.mybatis.service.UserService;

/**
 * mybatis-spring 通过 MapperScannerConfigurer 批量生成 Mapper接口
 *
 * @author ME
 * @date 2021/5/20
 */
public class TestMybatisScanXML {

    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(MapperScanConfig.class);

        UserService service = context.getBean(UserService.class);
        System.out.println("UserService: " + service.getUser(3));
        System.out.println();

        UserMapper mapper = context.getBean(UserMapper.class);
        System.out.println("UserMapper: " + mapper.getUser(1));
    }

    /** 配置类 */
    @Configuration
    @ImportResource("classpath:spring/mybatis/mybatisScanXML/mybatis-scan.xml")
    @EnableAspectJAutoProxy(proxyTargetClass = true)// 强制使用 Cglib动态代理
    public static class MapperScanConfig {
    }

}
